package com.xigua.JucOfBeautiful.chapterFive;

import java.util.Iterator;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2022/2/121:42
 */
public class COwListTest {

    private static volatile CopyOnWriteArrayList<String> copyOnWriteArrayList = new CopyOnWriteArrayList();

    public static void main(String[] args) throws InterruptedException {
        copyOnWriteArrayList.add("aaa");
        copyOnWriteArrayList.add("bbb");
        copyOnWriteArrayList.add("ccc");
        copyOnWriteArrayList.add("ddd");
        copyOnWriteArrayList.add("eee");


        Iterator<String> iterator = copyOnWriteArrayList.iterator();
        Thread thread = new Thread(()->{
            copyOnWriteArrayList.set(1,"fff");
            copyOnWriteArrayList.set(2,"ggg");
        });
        thread.start();

        thread.join();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }


    }

}
